package com.jml.jdk8.方法引用;


import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author:jml
 * @date: 2019/12/3 0003 22:50
 * @description：
 */
public class MethodReferenceTest004类名andNew {

    //Supplier不接受参数，返回一个值
    public String getString1(Supplier<String> supplier) {
        return supplier.get() + "test";
    }
    //Function接收一个参数返回有一个参数
    public String getString2(String str,Function<String,String> function) {
        return function.apply(str);
    }

    public Student getStudent(String str,Function<String,Student> function) {
        return function.apply(str);
    }

    public static void main(String[] args) {
        MethodReferenceTest004类名andNew methodReferenceTest = new MethodReferenceTest004类名andNew();
        Supplier supplier = () -> "";
        //这个就是String的空参构造
        Supplier supplier1 = String::new;
        //这个可以是String的有参参构造
        Function<String,String> function = String::new;
        System.out.println(methodReferenceTest.getString1(String::new));
        System.out.println(methodReferenceTest.getString2("jml",String::new));
        //这个可以是Student的一个参数的构造方法，返回一个Student
        Function<String,Student> function2 =Student::new;
        Student jml = methodReferenceTest.getStudent("jml", Student::new);
        System.out.println(jml.getName());
    }

}
